# -*- coding: utf-8 -*-

_UNICODE_DISPLAY_WIDTH_RANGE = (
    (126, 1),
    (159, 0),
    (687, 1),
    (710, 0),
    (711, 1),
    (727, 0),
    (733, 1),
    (879, 0),
    (1154, 1),
    (1161, 0),
    (4347, 1),
    (4447, 2),
    (7467, 1),
    (7521, 0),
    (8369, 1),
    (8426, 0),
    (9000, 1),
    (9002, 2),
    (11021, 1),
    (12350, 2),
    (12351, 1),
    (12438, 2),
    (12442, 0),
    (19893, 2),
    (19967, 1),
    (55203, 2),
    (63743, 1),
    (64106, 2),
    (65039, 1),
    (65059, 0),
    (65131, 2),
    (65279, 1),
    (65376, 2),
    (65500, 1),
    (65510, 2),
    (120831, 1),
    (262141, 2),
    (1114109, 1),
)


def get_str_display_width(s):
    ret = 0
    for o in s:
        o = ord(o)
        if o == 0xe or o == 0xf:
            continue

        not_found = True
        for num, wid in _UNICODE_DISPLAY_WIDTH_RANGE:
            if o <= num:
                ret += wid
                not_found = False
                break

        if not_found:
            ret += 1
    return ret
